import { Message } from '@arco-design/web-react';
import { apiCardSetTag } from '../../../api';
import { CardDetail } from '../refresh/types';
import LoadingMask from '../../../components/loadingMask';
import { confirmDialog } from '../../../components/dialog';
// 开关机
// 设置月底不停机 // operationType 1 新增 2 修改全部为新的 3 删除 4 单个替换 +oldTagDetailName
export async function handleSetTag(record: CardDetail,callBack?:Function) {
    let operationType = 1;
    if (record.tagNames?.includes('月底不停机')) {
        operationType = 0;
    }
    let modalRes = await confirmDialog({
        title: '月底不停机',
        content: `确定要${operationType === 0 ? '删除' : '设置'}月底不停机吗?`,
    });
    if (modalRes === 0) return;
    LoadingMask.show('正在设置...');
    try {
        let res = await apiCardSetTag({ type:operationType, id: record.id });
        let data = res.data;
        if (data.code === 200) {
            Message.success(data.msg ?? '操作成功');
            callBack && callBack()
        } else {
            Message.warning(data.msg ?? '操作失败');
        }
    } catch (e: any) {
        Message.error(e.message ?? '操作失败');
    } finally {
        LoadingMask.hide();
    }
}